package edu.aynu.service.impl;

import edu.aynu.entity.Judge;
import edu.aynu.dao.JudgeDao;
import edu.aynu.es.EsJudgeDao;
import edu.aynu.service.JudgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Judge)表服务实现类
 *
 * @author haha
 * @since 2021-05-20 14:39:14
 */
@Service("judgeService")
public class JudgeServiceImpl implements JudgeService {
    @Resource
    private JudgeDao judgeDao;

    @Autowired
    private EsJudgeDao esJudgeDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Judge queryById(Integer id) {
        return this.judgeDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Judge> queryAllByLimit(int offset, int limit) {
        return this.judgeDao.queryAllByLimit(offset, limit);
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @param judge 实例对象
     * @return 对象列表
     */
    @Override
    public List<Judge> queryAll(Judge judge) {
        return this.judgeDao.queryAll(judge);
    }

    /**
     * 新增数据
     *
     * @param judge 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Judge judge) {
        int i = this.judgeDao.insert(judge);
        List<Judge> judges = judgeDao.queryAll(judge);
        esJudgeDao.save(judges.get(0));
        return i;
    }

    /**
     * 修改数据
     *
     * @param judge 实例对象
     * @return 实例对象
     */
    @Override
    public int update(Judge judge) {
        return this.judgeDao.update(judge);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.judgeDao.deleteById(id) > 0;
    }
}
